using UnityEngine;
using System.Collections;

public class Bool : MonoBehaviour {
	public AudioClip WinAudio;
	GameObject a =null;
	GameObject b =null ;
	int sodiem=0;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {

		if(Input.GetMouseButtonDown(0))
		{
			RaycastHit2D hitInfo = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
			
			if(hitInfo.collider != null && hitInfo.collider.tag=="Card")
			{

				if(a!=null && b==null )
				{
					b= hitInfo.rigidbody.gameObject;
					b.collider2D.enabled=false;
					b.GetComponent<GetAnimation>().ShowTrue();
				}
				if(a==null)
				{
					a= hitInfo.rigidbody.gameObject;
					a.collider2D.enabled=false;
					a.GetComponent<GetAnimation>().ShowTrue();
				}

				if(a!=null && b!=null && a.name==b.name)
				{
					Debug.Log("match");
					sodiem++;
					if(sodiem==CreateImage.typeCard)
					{
						audio.PlayOneShot(WinAudio,0.5f);
					}
				}
				if(a!=null && b!=null && a.name!=b.name  )
				{

				
					StartCoroutine (waitUnFlip(a,b));
				}
				if(a!=null && b!=null)
				{
					a=null;b=null;
				}

			}
		}
	}
	IEnumerator waitUnFlip(GameObject a,GameObject b)
	{
		b.collider2D.enabled=true; 
		a.collider2D.enabled=true;
		yield return new WaitForSeconds(0.65f);
		//Destroy(b.GetComponent("FlipCard"));b.AddComponent("unFlipCard");
		//Destroy(a.GetComponent("FlipCard"));a.AddComponent("unFlipCard");
		a.GetComponent<GetAnimation>().HideTrue();
		b.GetComponent<GetAnimation>().HideTrue();
	}

}
